package ch.zhaw.cctd.domain.map;

import java.awt.Point;
import java.io.Serializable;

/**
 * Ein WayPoint ist ein Punkt mit einer Cooridinate und einem NextWayPoint. Die
 * Waypoints bilden einen Pfad auf dem sich die Creeps bewegen können.
 * 
 * @author Rolf
 * 
 */
public class WayPoint extends Point implements Serializable {

	/**
	 * Serializable ID
	 */
	private static final long serialVersionUID = -246970704345014090L;

	// Waypoint ID
	private String id;
	// NextWayPoint
	private WayPoint targetPoint;
	// NextWayPoint ID (Temporary)
	private String nextWayPointId;

	/**
	 * Default Constructor (Requires setTargetWayPoint to be called afterwards,
	 * if called directly)
	 * 
	 * @param id
	 * @param position
	 * @param nextWayPointId
	 */
	public WayPoint(String id, Point position, String nextWayPointId) {
		super(position);
		setId(id);
		setNextWayPointId(nextWayPointId);
	}

	/**
	 * Constructor with targetWayPoint support
	 * 
	 * @param id
	 * @param position
	 * @param nextWayPointId
	 * @param targetPoint
	 */
	public WayPoint(String id, Point position, String nextWayPointId, WayPoint targetPoint) {
		this(id, position, nextWayPointId);
		setTargetWayPoint(targetPoint);
	}

	/**
	 * Copy Constructor
	 * 
	 * @param w
	 */
	public WayPoint(WayPoint w) {
		this(w.id, new Point(w.x, w.y), w.nextWayPointId, w.targetPoint);
	}

	/**
	 * Returns the Target Point
	 * 
	 * @return Waypoint
	 */
	public WayPoint getTargetPoint() {
		if (targetPoint == null)
			throw new IllegalStateException("Target Point isn't set yet. Please set it before Reading it.");
		return targetPoint;
	}

	/**
	 * Set the Target WayPoint
	 * 
	 * @param targetPoint
	 */
	public void setTargetWayPoint(WayPoint targetPoint) {
		this.targetPoint = targetPoint;
	}

	/**
	 * Set the Waypoint ID
	 * 
	 * @param id
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * Get the Waypoint ID
	 * 
	 * @return
	 */
	public String getId() {
		return id;
	}

	/**
	 * Set nextWayPoint ID
	 * @param nextWayPointId
	 */
	private void setNextWayPointId(String nextWayPointId) {
		this.nextWayPointId = nextWayPointId;
	}

	/**
	 * Get NextWayPoint ID
	 * @return string
	 */
	public String getNextWayPointId() {
		return nextWayPointId;
	}

}
